package com.bvgol.examples.nio.zerocp.old;/**
 * @Classname OldIOClient
 * @Description TODO
 * @Date 2021/7/6 9:34
 * @Created by GUOCHEN
 */

import java.io.*;
import java.net.Socket;

/**
 * @program: my-spring-completely
 * @description:
 * @author: GUOCHEN
 * @create: 2021/07/06 09:34
 */
public class OldIOClient {
    public static void main(String[] args) throws IOException {
        Socket socket   = new Socket("localhost",7001);
        String filename = "D:\\idea_projects\\my-springboot-completely\\netty\\src\\main\\resources\\file01.txt";
        InputStream inputStream = new FileInputStream(filename);
        OutputStream out;
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        byte[] buffer = new byte[4096];
        long readCount = 0;
        long totalRead = 0;

        long startTime = System.currentTimeMillis();
        int read = inputStream.read(buffer);

        while (read>0){
            totalRead+=readCount;
            dataOutputStream.write(buffer);
        }

        System.out.println("发送的总字节数 :"+totalRead +" 历时: "+(System.currentTimeMillis()-startTime));
        dataOutputStream.close();
        socket.close();
        inputStream.close();
    }
}
